package com.parsifal.markdownwebview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("file:///android_asset/index.html");
        mWebView.addJavascriptInterface(this, "test");
    }

    @android.webkit.JavascriptInterface
    public void actionFromJs() {
        Log.e("test", "js调用了Native函数");
    }

    @android.webkit.JavascriptInterface
    public void actionFromJsWithParam(final String str) {
        Log.e("test", "js调用了Native函数传递参数：" + str);
    }
}
